package cnpm02.j2ee.group3.logic.dao.impl;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.Query;

import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;

import cnpm02.j2ee.group3.logic.dao.generic.AbstractEntityDaoImpl;
import cnpm02.j2ee.group3.model.Person;

@Stateless
@Name("personDao")
@AutoCreate
public class PersonDaoImp extends AbstractEntityDaoImpl<Person> implements PersonDao {

	@SuppressWarnings("unchecked")
	public List<Person> selectAll() {
		Query query = getEntityManager().createQuery(SELECT_ALL_QUERY);
		return query.getResultList();
	}
	
	public Person find(String login) {

		Query query = getEntityManager().createQuery(SELECT_PERSON_BY_LOGIN);
		query.setParameter("login", login);

		return (Person) query.getSingleResult();
	}
}
